using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
using System.Reflection;
using System.Threading;
using pop3dll;
using SMTPdll;

namespace pop3
{
    public partial class SMTPviewer : Form
    {
        bool isAttached = false;
        public SMTPviewer()
        {
            InitializeComponent();
            
        }
        public SMTPviewer(string from, string to, string subject, string body) 
        {
            InitializeComponent();
            fromB.Text = from;
            toB.Text = to;
            subjectB.Text = "Re: " + subject;
            messageB.Text = body;
        
        }
        public SMTPviewer(string from)
        {
            InitializeComponent();
            fromB.Text = from;
        }
        private void sendButton_Click(object sender, EventArgs e)
        {
            
            SMTPSender x = new  SMTPSender("mail.charter.net",isAttached);
            
            x.setToAddress(toB.Text);
            x.setFromAddress(fromB.Text);
            x.setSubject(subjectB.Text);
            x.setBody(messageB.Text);
            x.setfilename(attachTB.Text);

            if (!x.sendMessage())
            {
                MessageBox.Show("Message not sent");
                statusB.Text = x.resultLines;
               
               
               
            }
            else
            {

                MessageBox.Show("Message sent successfully");
                clearFields();
                statusB.AppendText(x.resultLines);
            }
            
        }

        public void clearFields()
        {
            toB.Clear();
            fromB.Clear();
            subjectB.Clear();
            messageB.Clear();
            attachTB.Clear();
            isAttached = false;

        }

        private void attachB_Click(object sender, EventArgs e)
        {
            OpenFileDialog o = new OpenFileDialog();
            DialogResult poofy = o.ShowDialog();
            if (poofy == DialogResult.OK)
            {
                attachTB.Text += o.FileName;
                MessageBox.Show(o.FileName.ToString());
                isAttached = true;
            }
        }
    }
}